package com.common.res;

import com.common.exception.code.BaseResponseCode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 封装响应数据
 */
@Data
public class DataResult<T> {
    @ApiModelProperty(value = "响应码")
    private int code;

    @ApiModelProperty(value = "响应信息")
    private String msg;

    @ApiModelProperty(value = "响应的数据")
    private T data;

    public DataResult(BaseResponseCode responseCode, T data){
        this.code = responseCode.getCode();
        this.msg = responseCode.getMsg();
        this.data = data;
    }

    public DataResult(BaseResponseCode responseCode){
        this.code = responseCode.getCode();
        this.msg = responseCode.getMsg();
        this.data = null;
    }

    public DataResult(int code, T data) {
        this.code = code;
        this.data = data;
        this.msg=null;
    }
    public DataResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public DataResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data=null;
    }

    public DataResult() {
        this.code = BaseResponseCode.SUCCESS.getCode();
        this.msg = BaseResponseCode.SUCCESS.getMsg();
        this.data=null;
    }

    public DataResult(T data) {
        this.code = BaseResponseCode.SUCCESS.getCode();
        this.msg = BaseResponseCode.SUCCESS.getMsg();
        this.data=data;
    }

    public static DataResult success(){
        return new DataResult();
    }

    public static <T>DataResult success(T data){
        return new DataResult(data);
    }

    public static <T>DataResult getResult(BaseResponseCode responseCode,T data){
        return new DataResult(responseCode,data);
    }

    public static DataResult getResult(BaseResponseCode responseCode){
        return new DataResult(responseCode);
    }

    public static <T>DataResult getResult(int code,String msg,T data){
        return new DataResult(code,msg,data);
    }

    public static DataResult getResult(int code,String msg){
        return new DataResult(code,msg);
    }
}
